package org.edith.shiro.response;


import org.edith.shiro.enums.ResponseEnum;

import java.io.Serializable;

public class CommonResponse<T> implements Serializable {

    private boolean success;
    private String code;
    private String message;
    private T data;

    private CommonResponse(boolean success, ResponseEnum responseEnum, T data) {
        this.success = success;
        this.message = responseEnum.getMessage();
        this.code = responseEnum.getCode();
        this.data = data;
    }

    public static <T> CommonResponse success(T data){
        return new CommonResponse<T>(true, ResponseEnum.SUCCESS,data);
    }
    public static  CommonResponse success(){
        return new CommonResponse(true,ResponseEnum.SUCCESS,null);
    }

    public static  CommonResponse failure(){
        return new CommonResponse(false,ResponseEnum.FAILURE,null);
    }

    public static  CommonResponse failure(ResponseEnum responseEnum){
        return new CommonResponse(false,responseEnum,null);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
